package sword_offer;

import common.TreeNode;

/**
 * @ClassName _28IsSymmetricTreeNode
 * @Description: 判断是否为对称的二叉树
 * @Author: yongliang.ma
 * @Create_time:2022/10/9 13:46
 */
public class _28IsSymmetricTreeNode {


    public boolean isSymmetric(TreeNode treeNode){
        if (treeNode == null)
            return true;

        return isSymmetric(treeNode.left, treeNode.right);
    }

    public boolean isSymmetric(TreeNode node1, TreeNode node2){
        if (node1 == null && node2 == null)
            return true;
        if ((node1 == null && node2 != null) || (node1 != null && node2 == null))
            return false;

        if (node1.val != node2.val)
            return false;

        return isSymmetric(node1.left, node2.right) && isSymmetric(node1.right, node2.left);
    }
}
